package com.ze.familyday.familyphotoframe;
/**
 * 		2013.9.8 	更新jpush客户端版本 @ze 
 * 		2013.9.15 	关闭jpush(@ze)，改为拉取模式伪推送@mouse ver1.6
 * 		2013.9.15 	添加debug模式查看版本信息  "VerCod";
 */
import java.util.List;
import java.util.Set;

import org.json.JSONObject;

import com.ze.commontool.JPushUtil;
import com.ze.commontool.NetHelper;
import com.ze.familyday.familyphotoframe.R;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
import android.app.Application;
import android.content.Context;
import android.os.PowerManager;
import android.util.Log;
import android.widget.Toast;

public class FamilyDayVerPMApplication extends Application {
	static Context appContext;
	
	public List<JSONObject> mList;
	  
	      
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
//		JPushInterface.setDebugMode(false);
//		JPushInterface.init(this);
//		JPushInterface.setLatestNotifactionNumber(this, 1);			// 最多3个推送同时出现在通知栏
		appContext = this;
	}
	static TagAliasCallback aliasCallback = new TagAliasCallback() {
		
		@Override
		public void gotResult(int code, String alias, Set<String> tags) {
			// TODO Auto-generated method stub
			String logs ;
			switch (code) {
			case 0:
				logs = "Set tag and alias success, alias = " + alias + "; tags = " + tags;
				Log.i("jpush", logs);
				break;
			
			default:
				logs = "Failed with errorCode = " + code + " " + alias + "; tags = " + tags;
				Log.e("jpush", logs);
				JPushUtil.showToast("绑定推送失败！请你重新登录重试！",appContext );
			}
			

		}
	};
	
	public static void bindJpush(final Context context, final String uidString)
	{
//		new Thread( new Runnable() {
//			
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				JPushInterface.setAliasAndTags(context, uidString, null,aliasCallback);
//				
//				String respon = NetHelper.getResponByHttpClient(String.format( context.getResources().getString( 
//						R.string.http_bindjpush),uidString ));
//				try {
//					JSONObject object = new JSONObject(respon);
//					if ( object.getInt("code") == 0 ) {
//						Log.v("jpush","bind success");
//					}else
//					{
//						Log.v("jpush","bind error");
//						Toast.makeText(context, "绑定帐号失败！", Toast.LENGTH_LONG).show();
//					}
//				} catch (Exception e) {
//					// TODO: handle exception
//					e.printStackTrace();
//				}
//			}
//		}).start();
	}
	
	public static void unBindJpush(final Context context, final String uidString)
	{
//		JPushInterface.setAliasAndTags(context, "", null);
//		new Thread( new Runnable() {
//			
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				String respon = NetHelper.getResponByHttpClient(String.format( context.getResources().getString( 
//						R.string.http_unbindjpush),uidString ));
//			}
//		}).start();
	}
	
}
